package com.gxwy.jiaoyi.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.gxwy.jiaoyi.form.JiaoYi;
import com.gxwy.jiaoyi.service.JiaoYiService;
import com.gxwy.yonghuziliao.form.YongHuZiLiao;
import com.gxwy.yonghuziliao.service.YongHuZiLiaoService;

@Controller
@RequestMapping("/jiaoyi")
public class ChaXunController {

	@Autowired
	private YongHuZiLiaoService service;
	
	@Autowired
	private JiaoYiService service1;
	
	@RequestMapping("/tozzmxcx")
	public String tozzmxcx(Model model,HttpSession session){
		String username=(String) session.getAttribute("username");
		List<YongHuZiLiao> list=service.findAll(username);			
		int size=list.size();
		model.addAttribute("yonghuziliao",list);
		model.addAttribute("size",size);
		return "zzmxcx";
	}
	
	@RequestMapping("/tozzmxcx1/{id}")
	public String tozzmxcx1(Model model,@PathVariable("id")Integer id){
		YongHuZiLiao yhzl=service.findById(id);
		model.addAttribute("yhzl",yhzl);
		return "zzmxcx1";
	}
	
	@RequestMapping("/tozzmxcx2")
	public String tozzmxcx2(Model model,@RequestParam("zhanghao")String zh,@RequestParam("qishiriqi")String qsrq,@RequestParam("jiezhiriqi")String jzrq){
		jzrq=jzrq+" 23:59:59";
		List<JiaoYi> list=service1.chaxunmingxi(zh, qsrq, jzrq);
		float jiaoyijine=0f;
		for(JiaoYi jy:list){
			if("0".equals(jy.getZhuanruzhuanchu())){			
				jiaoyijine+=jy.getJiaoyijine();
			}
		}
		model.addAttribute("jyje",jiaoyijine);
		model.addAttribute("list",list);
		return "zzmxcx2";
	}
}
